package com.ruoyi.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.inspection.domain.vo.GovernCheckTaskPlanItemVo;
import com.ruoyi.system.domain.equipment.EquipmentBasic;
import com.ruoyi.system.domain.vo.PreventionSecurityRiskVO;
import com.ruoyi.system.service.equipment.IEquipmentBasicService;
import org.apache.http.HttpRequest;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 主要设备Controller
 * 
 * @author ruoyi
 * @date 2025-03-17
 */
@RestController
@RequestMapping("/equipment/basic")
public class EquipmentBasicController extends BaseController
{
    @Autowired
    private IEquipmentBasicService equipmentBasicService;

    /**
     * 查询主要设备列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:basic:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentBasic equipmentBasic)
    {
        startPage();
        List<EquipmentBasic> list = equipmentBasicService.selectEquipmentBasicList(equipmentBasic);
        return getDataTable(list);
    }

    /**
     * 获取主要设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:basic:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentBasicService.selectEquipmentBasicById(id));
    }

    /**
     * 新增主要设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:basic:add')")
    @Log(title = "主要设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentBasic equipmentBasic)
    {
        return toAjax(equipmentBasicService.insertEquipmentBasic(equipmentBasic));
    }

    /**
     * 修改主要设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:basic:edit')")
    @Log(title = "主要设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentBasic equipmentBasic)
    {
        return toAjax(equipmentBasicService.updateEquipmentBasic(equipmentBasic));
    }

    /**
     * 删除主要设备
     */
    @PreAuthorize("@ss.hasPermi('equipment:basic:remove')")
    @Log(title = "主要设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(equipmentBasicService.deleteEquipmentBasicByIds(ids));
    }



    /**
     * 导出主要设备列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:basic:export')")
    @Log(title = "主要设备", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentBasic equipmentBasic)
    {
        List<EquipmentBasic> list = equipmentBasicService.selectEquipmentBasicList(equipmentBasic);
        ExcelUtil<EquipmentBasic> util = new ExcelUtil<EquipmentBasic>(EquipmentBasic.class);
        util.exportExcel(response, list, "主要设备数据");
    }

    /**
     * 导入
     *
     * @param file
     * @return
     * @throws Exception
     */
    @Log(title = "导入主要设备", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('equipment:basic:export')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, HttpServletRequest request) throws Exception {
        ExcelUtil<EquipmentBasic> util = new ExcelUtil<>(EquipmentBasic.class);
        List<EquipmentBasic> list = util.importExcel(file.getInputStream());

        String message = equipmentBasicService.importHandler(list, getUsername());
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<EquipmentBasic> util = new ExcelUtil<>(EquipmentBasic.class);
        util.importTemplateExcel(response,"主要设备");
    }
}
